
<template>
<el-container style=" border: 1px solid #eee" >

  <el-aside   style="min-height: 700px;; background-color: rgb(238, 241, 246)">
    <img src="../../static/img/chiaklogo.png" />
    <el-menu
    @open="handleOpen"
    @close="handleClose"
    @select="handleSelect"
    :default-active="this.$route.path"
    :default-openeds='openeds'
    router
    >
     <el-menu-item index="/">
            <i class="el-icon-menu"></i>
            <span slot="title" >首页</span>
          </el-menu-item>

      <el-submenu index="2" >
        <template slot="title"><i class="el-icon-user-solid" ></i>用户管理</template>
          <el-menu-item index="/user/page1">用户列表</el-menu-item>
          <el-menu-item index="/user/page2">添加用户</el-menu-item>
      </el-submenu>
      <el-submenu index="3">
        <template slot="title"><i class="el-icon-menu"></i>新闻管理</template>
          <el-menu-item index="/new/page3">新闻列表</el-menu-item>
          <el-menu-item index="/new/page4">添加新闻</el-menu-item>
        </el-submenu>
        <el-submenu index="4">
          <template slot="title"><i class="el-icon-unlock"></i>用户权限</template>
            <el-menu-item index="/userkey/userkeys">用户权限列表</el-menu-item>

          </el-submenu>


    </el-menu>
  </el-aside>

  <el-container>
    <el-header >






      <el-dropdown>
        <i class="el-icon-setting" style="margin-right: 15px"></i>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>查看</el-dropdown-item>
          <el-dropdown-item>新增</el-dropdown-item>
          <el-dropdown-item @click.native="outlogin">退出</el-dropdown-item>
         </el-dropdown-menu>
        </el-dropdown>
       <span>{{user}}</span>
     </el-header>
    <transition  name="fade" appear>
     <!-- 左边组件 -->
      <!-- <left v-if="show"></left> -->
      <Breadcrumb class="breadcrumb"></Breadcrumb>
    </transition>

 <transition  name="fade" appear>
    <router-view class="from-id"></router-view>
</transition>

  </el-container>
</el-container>
</template>
<style space>
  .el-header {
    background-color: #333333;
    color: white;
    line-height: 60px;
  }

  .el-aside {
    color: royalblue;
  }

  .is-opened{
    background-color: #686868;

    }
    .el-submenu .el-submenu__title{
      background-color: #333333;
      color: white;

    }
     /* background-color: #333333; */
    .el-submenu__title:hover{

      color: black;

    }
    .el-aside img{
      width: auto;
      height: 60px;
    }
.from-id{
  margin-top:10px;
  margin-left: 20px;
}
.el-header{
  text-align: right;
  font-size: 12px;
}
.breadcrumb{
  margin-top:10px;
  margin-left: 20px;
  padding: 5px;
  border-bottom: white solid 10px;
  border-left: #008000 solid 10px;
  border-top: white solid 10px;

}



.fade-enter-active, .fade-leave-active {
		  transition: opacity 3s;
		    transition: all .3s ease;

		}
		.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {

		  opacity: 0;
		  transform: translateX(10px);

		}

       .fade-enter-to,.fade-leave{
              opacity: 0;
              transform: translateX(10px);

       }

</style>



<script>
import Breadcrumb from "./templates/Breadcrumb";

  export default {
    data() {

      return {
        pathto:'',
        openeds:[],
        user:"",


      }
    },
     mounted() {
        // 在这里可以通过组件的 $refs 获取到子组件的实例
        // 可以认为，在这里子组件实例化完毕
        this.user=this.$vuecookies.get("token");
        //console.log(localStorage.getItem("token"));
      },



     components:{
       //导航栏组件
        Breadcrumb,
      },


     methods: {
          handleOpen(key, keyPath) {
           console.log(key, keyPath);
           switch (key){
            
             case "2":
              this.$router.push("/user/page1");
             break;
             case "3":
                this.$router.push("/new/page3");
             break;
             case "4":
                  this.$router.push("/userkey/userkeys");
              break;
             default:
               break;
           }

          },
          handleClose(key, keyPath) {

            //console.log(key, keyPath);
          }
          ,
          handleSelect(key, keyPath) {
            //用index+路由去掉下面的（switch）
            // switch (key){
            //   case "/user/page1":
            //   // this.$router.push("/user/page1");
            //     break;
            //     case "/user/page2":
            //     // this.$router.push("/user/page2");
            //       break;
            //   default:
            //     break;
            // }

          },
          outlogin(){
           // console.log("注销");
            this.$vuecookies.remove("token");
            this.$vuecookies.remove("tokenid");
            this.$router.push("/login");
          },
        },

        watch:{
          $route(to,from){
            //console.log(to.path);
             this.pathto=to.path;
             if(to.path==="/"){
                this.openeds=[];
             }


          }
        },


  };
</script>
